package com.datatypes;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class ActivityTracks {

	private List<Activity> activities = null;

	public ActivityTracks() {
		activities = new ArrayList<Activity>();
	}

	public ActivityTracks(User user) {
		super();
		user.setLast_updated((Calendar.getInstance()).getTime().getTime());
	}

	public ActivityTracks(List<Activity> listOfActivity) {
		this.activities = listOfActivity;
	}

	public void addActivity(Activity activity, User user) {
		activities.add(activity);
		if (user != null)
			user.setLast_updated((Calendar.getInstance()).getTime().getTime());
	}

	public void removeActivity(Activity activity, User user) {
		activities.remove(activity);
		user.setLast_updated((Calendar.getInstance()).getTime().getTime());
	}

	public List<Activity> getActivityList() {
		return activities;
	}

	public Activity getActivity(int num) {
		return activities.get(num);
	}

	public Activity getActivity(String id) {
		for (Activity a : activities) {
			if (id.equals(a.getActivity_id()))
				return a;
		}
		return null;
	}

	public void updateActivity(Activity activity) {
		for (Activity a : activities) {
			if (activity.getActivity_id().equals(a.getActivity_id())) {
				activities.remove(a);
				activities.add(activity);
			}
		}
	}
}
